package com.wandian.setting.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.utils.GlideUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.setting.R;
import com.wandian.setting.bean.DynamicDataBean;


/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description UserInfoSDRecycleAdapter
 **/
public class UserInfoSDRecycleAdapter extends BaseQuickAdapter<DynamicDataBean, BaseViewHolder> {


    private int number = 0;
    private String isMine = "0";
    public UserInfoSDRecycleAdapter(int layoutResId,String isMine) {
        super(layoutResId);
        this.isMine = isMine;
    }
    private DeleteClink deleteClink;

    public DeleteClink getDeleteClink() {
        return deleteClink;
    }

    public void setDeleteClink(DeleteClink deleteClink) {
        this.deleteClink = deleteClink;
    }

    public interface DeleteClink{
        void deleteId(String id,int index);
    }


    @Override
    protected void convert(BaseViewHolder helper, DynamicDataBean item) {


        TextView tv_sd_text = helper.getView(R.id.tv_sd_text);
        tv_sd_text.setText(item.getContent()+"");
        TextView tv_sd_time = helper.getView(R.id.tv_sd_time);
        tv_sd_time.setText(item.getCreateTime()+"");

        ImageView iv_sd_delete = helper.getView(R.id.iv_sd_delete);
        iv_sd_delete.setOnClickListener(v -> deleteClink.deleteId(item.getId(),helper.getLayoutPosition()));
        if(!UIUtils.isEmpty(isMine) && isMine.equals("0")){
            iv_sd_delete.setVisibility(View.GONE);
        }else {
            iv_sd_delete.setVisibility(View.VISIBLE);
        }
        ImageView iv_sd_pic_1 = helper.getView(R.id.iv_sd_pic_1);
        if(!UIUtils.isEmpty(item.getImgList()) && item.getImgList().size()>0 && !UIUtils.isEmpty(item.getImgList().get(0))){
            iv_sd_pic_1.setVisibility(View.VISIBLE);
            //获取图片真正的宽高
            GlideUtil.loadImgAutoSize(mContext,item.getImgList().get(0),iv_sd_pic_1);
            iv_sd_pic_1.setOnClickListener(v -> {
                if(!UIUtils.isEmpty(item)){
                    Bundle bundle = new Bundle();
                    bundle.putString("file_type","pic");
                    bundle.putString("file_path",item.getImgList().get(0));
                    ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_CHECK_FILE).with(bundle).navigation();
                }
            });
        }else {
            iv_sd_pic_1.setVisibility(View.GONE);
        }

    }
}
